package com.aiyun.websocket.tiowebsocketdemo.web;


import org.tio.core.Tio;
import org.tio.server.ServerTioConfig;
import org.tio.websocket.common.WsPacket;
import org.tio.websocket.common.WsResponse;

import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class SendMessage {

	private final ServerTioConfig serverTioConfig;

	public SendMessage(ServerTioConfig serverTioConfig) {
		this.serverTioConfig = serverTioConfig;
	}

	@PostMapping("/api/send")
	public String send(String user, String message){
		Tio.sendToUser(serverTioConfig, user, WsResponse.fromText(message, WsPacket.CHARSET_NAME));
		return "send success";
	}
}
